﻿///<reference path="../../../scripts/jquery-1.4.4.min.js" />
///<reference path="../../scripts/kooboo/kooboo.form.js" />


//init controls

$(function () {
    for (var i = 0; i < controls.length; i++) {
        var control = controls[i];
        $(".webcontrol-selector").append($("<option></option>").val(control.Name).html(control.Name));
    }

    $(".webcontrol-selector").change(changeWebControl).blur(changeWebControl);


    $("form").submit(function (e) {
        e.preventDefault();
        $(this).ajaxPost({ success: function () {
            window.location.href = list_action;
        }
        });
        return false;
    });

    //Step link
    $('.step-link').click(function () {
        target = $(this).attr("href");
        step = target.replace("#", "step-");
        $('.step-content').addClass("hide");
        $(target).removeClass("hide");
        $('.step li.current').removeClass("current");
        $('.step').children('li.' + step).addClass("current");
    });


    $("input[type=checkbox][name=HasSummary]").change(function () {
        if ($(this).attr("checked") == true) {
            $("#custom-field-container .field-summary").removeClass("hide");
        } else {
            $("#custom-field-container .field-summary").addClass("hide");
        }
    });

    $("input[type=checkbox][name=HasDescription]").change(function () {
        if ($(this).attr("checked") == true) {
            $("#custom-field-container .field-description").removeClass("hide");
        } else {
            $("#custom-field-container .field-description").addClass("hide");
        }
    });

    $("input[type=checkbox][name=HasPackageSize]").change(function () {
        if ($(this).attr("checked") == true) {
            $("#custom-field-container .field-size").removeClass("hide");
        } else {
            $("#custom-field-container .field-size").addClass("hide");
        }
    });

    $("input[type=checkbox][name=HasWeight]").change(function () {
        if ($(this).attr("checked") == true) {
            $("#custom-field-container .field-weight").removeClass("hide");
        } else {
            $("#custom-field-container .field-weight").addClass("hide");
        }
    });

});


    function changeWebControl(e) {
        var selected = $(this).val();

        var datatypeSelector = $(".datatype-selector");

        datatypeSelector.empty();

        for (var i = 0; i < controls.length; i++) {

            var ctrl = controls[i];
            if (ctrl.Name == selected) {


                for (var n = 0; n < ctrl.DataFormats.length; n++) {
                    var option = ctrl.DataFormats[n];
                    datatypeSelector.append($("<option></option>").val(option.Value).html(option.Name));
                }

                if (ctrl.DataFormats.length > 1) {
                    datatypeSelector.parent().parent().removeClass("hide");
                } else {
                    datatypeSelector.parent().parent().addClass("hide");
                }
            }
        }
    }

